<template>
  <!-- 运营管理-官网设置 -->
  <div class="officialwebsite_set">
    <div class="content-main" v-if="detailset.visible">
		  <owDetailset ref="ow_detailset" @openTemplateSelect="showTemplateselectPopup" :detailset='detailset.data'></owDetailset>
      <!-- <owTemplateedite ref="ow_templateedite" :templateedite='templateedite.data'></owTemplateedite> -->
      
    </div>
    <!-- 选择模板 -->
    <el-dialog class="ow_templateselectPopup noscrollbar"
     :modal="false"
     :title="templateselectPopup.title"
     :close-on-click-modal="false"
     :close-on-press-escape="false"
     :show-close="templateselectPopup.showCloseBtn"
     :visible.sync="templateselectPopup.visible">
      <templateselect ref="ow_templateselect" :templateselect='templateselectPopup' @selectCallBack="updateSelectTemplate"></templateselect>
    </el-dialog>
  </div>
</template>

<script>
import templateselect from './common/ow_templateselect'
import owDetailset from './common/ow_detailset'
import owTemplateedite from './common/ow_templateedite'
export default {
  components:{templateselect,owDetailset,owTemplateedite},
  data() {
    return {
      /**选择模板 */
      templateselectPopup:{
        title:'模板选择',
        visible:false,
        data:null,
        showCloseBtn:false
      },
      /**官网详情设置 */
      detailset:{
        visible:false,
        data:{}
      },
      /**模板编辑 */
      templateedite:{

      },
      userLevel:-1
    };
  },
  methods: {
    init(){
      // let user=JSON.parse(tool.getItem(window.lsKey.user));
      let self=this;
      self.detailset.visible=false;
      // debugger
      //机构管理员
      if(this.userLevel==1){
        self.templateselectPopup.visible=true;
        self.detailset.visible=false;
        self.templateselectPopup.showCloseBtn=false;
        if(self.$refs.ow_templateselect)
          self.$refs.ow_templateselect.init();
        else
          self.$nextTick(_ => {
            self.$refs.ow_templateselect.init();
          });
      }
      //校区
      else
        //判断该校区是否已经选择模板
        api.getSitetemplateInUseById({campusId:this.$store.state.campusId}).then(function(d){
          // console.log(d)
          if(d.info){
            self.templateselectPopup.visible=false;
            self.detailset.visible=true;
            self.templateselectPopup.showCloseBtn=true;
            self.formateData(d.info)
            self.detailset.data=d.info;
            self.$nextTick(_ => {
              self.$refs.ow_detailset.updateData();
            });
            
          }
          else{
            self.templateselectPopup.visible=true;
            self.detailset.visible=false;
            self.templateselectPopup.showCloseBtn=false;
            if(self.$refs.ow_templateselect)
              self.$refs.ow_templateselect.init();
            else
              self.$nextTick(_ => {
                self.$refs.ow_templateselect.init();
              });
            // self.$nextTick(_ => {
            //   self.$refs.ow_detailset.init();
            // });
          }
        });
    },
    /**格式化数据 */
    formateData(data){
      for(let i=0;i<data.columnViews.length;i++){
        data.columnViews[i].modelContent.contentData=JSON.parse(data.columnViews[i].modelContent.contentData);
      }
    },
    campusChange : function(campusId) { //校区改变
      this.init();
    },
    /**根据角色权限限制操作 */
    disableOperationByRole() {
      switch (this._userInfo.roleMode) {
        //超级管理员
        case 0: {
        
          break;
        }
        //机构管理员
        case 1: {
          this.userLevel=1;
          break;
        }
        //校区管理员
        case 2: {
          this.userLevel=2;
          break;
        }
      }
      // console.log(this.userLevel)
    },
    showTemplateselectPopup(){
      this.templateselectPopup.showCloseBtn=true;
      this.templateselectPopup.visible=true;
      if(this.$refs.ow_templateselect)
        this.$refs.ow_templateselect.init();
    },
    updateSelectTemplate(d){
      this.detailset.data=d;
      if(!this.detailset.visible){
        this.detailset.visible=true;
        this.$nextTick(_ => {
          this.$refs.ow_detailset.init();
        });
      }
      else{
        this.$refs.ow_detailset.init();
      }
        // this.detailset.visible=true;
        // self.$nextTick(_ => {
        //   self.$refs.ow_detailset.init();
        // });
    }
	
  },
  mounted() {
    this._userInfo = tool.getItem(lsKey.user, true); //得到当前用户信息
    this.disableOperationByRole();

	  this.init();
  },
  computed: {},
  watch: {},
  created: function() {}
};
</script>

<style lang="scss">
.officialwebsite_set {
  .content-main {
    margin: 0.14rem auto;
    min-width: 15.48rem;
    width: 15.48rem;
    padding: 0.2rem 0.32rem 0.2rem 0.32rem;
    height: auto;
    background: #fff;
    border: 0.01rem solid #ededed;
    border-radius: 0.1rem;
    box-shadow: 0 0.02rem 0.38rem 0 #3885f81f, 0 0 0.06rem 0 #3885f81f;
	  color: #333333;
    
    
  }
  
  // 滚动条
  .noscrollbar{
    overflow: hidden;
  }
  .scrollbarstyle::-webkit-scrollbar {
    width: 0.1rem;
    height: 0.1rem;
  }
  .scrollbarstyle::-webkit-scrollbar-thumb {
    border-radius: 0.5rem;
    background: rgb(1, 10, 32);
  }
  .scrollbarstyle::-webkit-scrollbar-track {
    background: #F2F6FC;
  }
}
</style>